<?php
namespace Admin\Controller;
use Think\Controller;
class UserController extends Controller 
{
    public function login()
    {
    	$this->display();
    }

    public function checklogin()
    {
    	$name = $_POST['name'];
    	$password = MD5($_POST['password']);
    	$admin = M('admin');
    	$admininfo = $admin->where('name="'.$name.'"')->find();
    	if (!empty($admininfo)) {
    		if ($admininfo['password']==$password) {
    			session('name',$admininfo['name']);
    			$this->success('登录成功', './index');
    		}else{
    			$this->error('密码错误');
    		}
    	}else{
    		$this->error('用户名不存在');
    	}
    }

    public function index()
    {
    	$name = session('name');
    	$this->assign('name',$name);
    	$this->display();
    }
    
    public function pass()
    {
    	$name = session('name');
    	$this->assign('name',$name);
    	$this->display();
    }
    //修改密码
    public function resetpass()
    {
    	$name = session('name');
    	$mpass = MD5($_POST['mpass']);
    	$newpass = MD5($_POST['newpass']);
    	$admin = M('admin');
    	$admininfo = $admin->where('name="'.$name.'"')->find();
    	if ($admininfo['password']==$mpass) {
    		$admin->password = $newpass;
    		$admin->where('name="'.$name.'"')->save();
    		$this->success('修改成功', '/thinkphp/admin/user/pass');
    	}else{
    		$this->error('您输入的原始密码不正确');
    	}
    }

    public function welcome()
    {
        $name = session('name');
        $this->assign('name',$name);
        $this->display();
    }
}